// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/order/api/AppWorkOrderApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/order/model/AppQueryWorkOrderListReq'
import InfoClass from '@api/order/model/AppCountStatusQuantityReq'
import BaseClass from '@api/order/model/AppWorkOrderDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'workOrderDto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(param, TIP = '查询工单统计') {
    const DTO = CORE.grpcDTO(InfoClass, param)
    const resp = await CORE.grpc(TIP, CLIENT, 'countAppStatusQuantity', DTO)
    return resp.statusQuantity || {}
  },

  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询我的工单') {
    const DTO = CORE.grpcDTO(ListClass, param, COM, BASE)
    DTO.setStatus(param.statusList.split(','))
    const resp = await CORE.grpc(TIP, CLIENT, 'queryAppWorkOrderList', DTO)
    return [resp.comQuery.totalCount, resp.workOrderDto || []]
  },
}
